﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TDAPIOLELib;
using System.IO;

namespace QCCure.Core
{
    [Serializable]
    public class QCAttachment
    {
        private IAttachment attachment;

     
        public QCAttachment(IAttachment attachment)
        {
         
            this.attachment = attachment;
        }

        public string Name { get { return attachment.Name; } }
        public string FileName { get { return attachment.FileName; } }
        public int FileSize { get { return attachment.FileSize; } }

        public void Download()
        {
            attachment.Load(true, new FileInfo(".").FullName);
        }

        // override object.Equals
        public override bool Equals(object obj)
        {           
            if (obj == null || GetType() != obj.GetType())
            {
                return false;
            }

            QCAttachment other = obj as QCAttachment;

            return StringComparer.CurrentCulture.Equals(attachment.FileName, other.attachment.FileName) &&
                   StringComparer.CurrentCulture.Equals(attachment.FileSize, other.attachment.FileSize);
        }

        // override object.GetHashCode
        public override int GetHashCode()
        {
            int filenameHashCode = attachment.FileName != null ? attachment.FileName.GetHashCode() : 0;
            int filesizeHashCode = attachment.FileSize.GetHashCode();
            return filenameHashCode ^ ((int)filesizeHashCode >> 32);
        }

        public override string ToString()
        {
            return attachment.Name + " [ " + attachment.FileSize + " ]";
        }

    }
}
